"""this script is used to visualize the point cloud of the mesh
"""

# %%
import numpy as np
import pyvista as pv
from pyvista import CellType
# node data
# these points will all be shared between the cells
points = np.array(
    [
        [0.0, 0.0, 0.0],
        [1.0, 0.0, 0.0],
        [0.5, 0.0, 0.0],
        [1.0, 1.0, 0.0],
        [1.0, 0.5, 0.0],
        [0.0, 1.0, 0.0],
        [0.5, 1.0, 0.0],
        [0.0, 0.5, 0.0],
        [0.5, 0.5, 0.0],
        [1.0, 0.0, 0.5],
        [1.0, 0.0, 1.0],
        [0.0, 0.0, 0.5],
        [0.0, 0.0, 1.0],
        [0.5, 0.0, 0.5],
        [0.5, 0.0, 1.0],
        [1.0, 1.0, 0.5],
        [1.0, 1.0, 1.0],
        [1.0, 0.5, 0.5],
        [1.0, 0.5, 1.0],
        [0.0, 1.0, 0.5],
        [0.0, 1.0, 1.0],
        [0.5, 1.0, 0.5],
        [0.5, 1.0, 1.0],
        [0.0, 0.5, 0.5],
        [0.0, 0.5, 1.0],
        [0.5, 0.5, 0.5],
        [0.5, 0.5, 1.0],
    ],
)
# 定义单元的连通性,第一列是单元节点个数,后续是节点编号(0-based)
cells = np.array(
    [
        [8, 0, 2, 8, 7, 11, 13, 25, 23],
        [8, 2, 1, 4, 8, 13, 9, 17, 25],
        [8, 7, 8, 6, 5, 23, 25, 21, 19],
        [8, 8, 4, 3, 6, 25, 17, 15, 21],
        [8, 11, 13, 25, 23, 12, 14, 26, 24],
        [8, 13, 9, 17, 25, 14, 10, 18, 26],
        [8, 23, 25, 21, 19, 24, 26, 22, 20],
        [8, 25, 17, 15, 21, 26, 18, 16, 22],
    ],dtype=int)

# 定义单元类型数组,每个单元类型对应一个整数
celltypes = CellType.HEXAHEDRON*np.ones(cells.shape[0],dtype=int)
# 初始化pyvista的UnstructuredGrid对象
grid = pv.UnstructuredGrid(cells, celltypes, points)
# 显示网格
# grid.plot(show_edges=True, color='w', point_size=10)

point_cloud=pv.PolyData(points[:9,:])




p=pv.Plotter()
# 给plotter()添加网格和控制这个网格显示的参数
p.add_mesh(grid,show_edges=True, color='r',style='wireframe')
# 将点云加入绘图器,并且设置点的大小和颜色
p.add_mesh(point_cloud,color='b',point_size=15,render_points_as_spheres=True)
p.show()


# %%

import pyvista as pv
from pyvista import examples
mesh = examples.load_random_hills()
arrows = mesh.glyph(
    scale="Normals", orient="Normals", tolerance=0.05
)
pl = pv.Plotter()
actor = pl.add_mesh(arrows, color="black")
actor = pl.add_mesh(
    mesh,
    scalars="Elevation",
    cmap="terrain",
    show_scalar_bar=False,
)
pl.show()
# %%
g = pv.UnstructuredGrid()
g.points=np.random.rand(10,3)
# %%
